#ifndef __ASYNC_FILE_LOADER__
#define __ASYNC_FILE_LOADER__

#include <e32base.h>
#include <f32file.h>
#include "CActiveHelper.h"

class CAsyncFileLoader;

struct MAsyncFileLoaderCallback
	{
	virtual void MAsyncFileLoaderCallbackRunL(CAsyncFileLoader* aSource, TInt aStatus, RBuf8& aBuf) = 0;
	};

class CAsyncFileLoader : public MActiveHelperCallback<RFile*>
	{
private:
	RBuf8 iBuf;
	CActiveHelper<RFile*>* iFileHelper;
	TBool iLoading;
	RFile iFile;
	MAsyncFileLoaderCallback* iTarget;
	virtual void MActiveHelperCallbackRunL(CActiveHelper<RFile*>* aActiveHelper, RFile* aUserData);
	virtual TInt MActiveHelperCallbackRunError(CActiveHelper<RFile*>* aActiveHelper, RFile* aUserData, TInt aError);
	virtual void MActiveHelperCallbackDoCancel(CActiveHelper<RFile*>* aActiveHelper, RFile* aUserData);
	CAsyncFileLoader();
	void ConstructL();
public:
	static CAsyncFileLoader* NewLC();
	static CAsyncFileLoader* NewL();
	virtual ~CAsyncFileLoader();
	TInt LoadFileL(RFs& aFs, const TDesC& aFileName, MAsyncFileLoaderCallback* aTarget, TInt aSeekOffset = 0, TInt aLength = -1);
	void Cancel();
	TBool Loading() const;
	};

#endif
